<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>

<body>
    <button class="btn">注册用户</button>
    <script src="../js/axios.min.js"></script>
    <script>
        // 注册用户: http: //hmajax.itheima,net/api/register
        //     请求方法: POST
        // 参数名:
        //     username: 用户名(中英文和数字组成, 最少8位)
        //      password: 密码(最少6位)

        document.querySelector('.btn').addEventListener('click', () => {
            axios({
                url: 'https://hmajax.itheima.net/api/register',
                method: 'post',
                data: {
                    username: '黑马no1he123',
                    password: '7654321'
                }
            }).then(result => {
                // 成功
                console.log(result)
            }).catch(error => {
                // 失败
                // 处理错误信息
                console.log(error);
                console.log(error.response.data.message); //账号被占用
                alert(error.response.data.message)
            })
        })
    </script>
</body>

</html>